<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * User Application: Permissions Management Class
 * Started: September 23, 2009 06:57 PM
 * Script version: 1.0
 +------------------------------------
 */
class perm{
	public function getValue($permission_required){
		global $view, $db, $lang;
		$key = new permissionkey($permission_required);
		if($key->getStatus() === false){
			trigger_error("Permission Key {$permission_required} does not exist!");
		}
		if(isset($_SESSION["cf_username"], $_SESSION["cf_controller"])){
			$userController = unserialize($_SESSION["cf_controller"]);
			$group = $userController->group;
			if($group->getStatus() === false){
				trigger_error("Group assigned to user logged in does not exist!");
			}
			$val = new permissionvalue($permission_required, $group->getPermMaskID());
			if($val->getStatus() === false){
				$permission_value = $key->getDefaultValue();
			}
			else{
				$permission_value = $val->getValue();
			}
		}
		else{
			$permission_value = $key->getDefaultGuestValue();
		}
		return $permission_value;
	}
	
	public function noPermissionError(){
		global $view, $lang;
		$view->writeIn($view->inlineError($lang->getByKey("core.permdenied")));
	}
}